#pragma once
#include <iostream>
#include <string>
#include "Protocal.hpp"

using namespace protocol_ns;

class Calculate
{
public:
    Response Excute(const Request &req)
    {
        char oper = req._oper;
        Response res;
        switch (oper)
        {
        case '+':
        {
            res._result = req._x + req._y;
            res._code = 0;
        }
        break;
        case '-':
        {
            res._result = req._x - req._y;
            res._code = 0;
        }
        break;
        case '*':
        {
            res._result = req._x * req._y;
            res._code = 0;
        }
        break;
        case '/':
        {
            if (req._y == 0)
            {
                res._code = 1;
            }
            else
            {
                res._result = req._x / req._y;
                res._code = 0;
            }
        }
        break;
        case '%':
        {
            if (req._y == 0)
            {
                res._code = 1;
            }
            else
            {
                res._result = req._x % req._y;
                res._code = 0;
            }
        }
        break;
        default:
            res._code = 2;
            break;
        }
        return res;
    }
};
